<?php
namespace app\index\model;
use think\Model;

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/22
 * Time: 16:04
 */
class Order extends Model{
	protected $table = 'boc_order';
    protected $connection = 'JXC';
    public function getcount($where,$ts,$te){
        if ($ts && $te) {
            $data=Order::where($where)->where('timeline', 'between time', [$ts, $te])->count();
        }else{
            if ($ts) {
                $data=Order::where($where)->whereTime('timeline', '>=', $ts)->count();
            }elseif ($te) {
                $data=Order::where($where)->whereTime('timeline', '<=', $te)->count();
            }else{
                $data=Order::where($where)->count();
            }
        }
        return $data;
    }
    public function getlist($where,$limit,$start=0,$order=false,$fields="*"){
//        $validate=new \app\index\validate\Manager();
//        if(!$validate->check($param)){
//            return $this->returnMsg('1002','');
//        }
        if (!$order) {
        	$order=array('id' => 'desc');
        }
        $data=Order::where($where)->limit($start,$limit)->order($order)->select();
        return $data;
    }
    public function cancelorder($where){
        $data=Order::where($where)->update(['status' => 2,'cancetime' => time()]);
        if ($data) {
        	return true;
        }else{
        	return false;
        }
    }
    public function add($data){
        $data=Order::insertGetId($data);
        return $data;
    }
    public function finishorder($where){
        $data=Order::where($where)->update(['status' => 1,'paytime' => time()]);
        if ($data) {
        	return true;
        }else{
        	return false;
        }
    }
    public function getone($where){
        $data=Order::where($where)->find();
        return $data;
    }
    public function updateorder($updates,$where){
        $data=Order::save($updates,$where);
        return $data;
    }
}